# Maintainer: George Rawlinson <grawlinson@archlinux.org>
# Contributor: lukas <lukas <dot> graetz <at> web <dot>  de>
# Contributor: Graham Edgecombe <graham@grahamedgecombe.com>

pkgname=cfr
pkgver=0.152
pkgrel=2
pkgdesc='Another Java decompiler'
arch=('any')
url='https://www.benf.org/other/cfr/'
license=('MIT')
depends=('java-runtime')
makedepends=('git' 'maven' 'jdk8-openjdk')
_commit='68477be3ff7171ee17ddd1a26064b9b253f1604f'
source=(
  "$pkgname::git+https://github.com/leibnitz27/cfr#commit=$_commit"
  "github.com-leibnitz27-cfr_tests::git+https://github.com/leibnitz27/cfr_tests"
  'wrapper.sh'
  'maven-repro.patch'
)
b2sums=('SKIP'
        'SKIP'
        'a64a64c44b790f87136bff0fda79ec077bfe156ff9b4cb4a47c77dede07dcb5334f5b6443e1228ebd8442b48c7a6f86dde99a299de7decb2aa7205de66e3b8ce'
        '68c34fe8ea6a91ee58561b86cdb34020ef9a4ac3fda65f67c8a5eb3386546d5416a05f2a02f86c83eee4be9b63859297d563fe2908d8bec5fa1eacb616b2e573')

pkgver() {
  cd "$pkgname"

  git describe --tags | sed 's/^v//'
}

prepare() {
  cd "$pkgname"

  # prepare git submodules
  git submodule init

  git config submodule.decompilation-test/test-data.url "$srcdir/github.com-leibnitz27-cfr_tests"

  git -c protocol.file.allow=always submodule update

  # ensure reproducible builds
  patch -p1 -i "$srcdir/maven-repro.patch"
}

build() {
  cd "$pkgname"

  # Force the system to build the package using JDK 8
  export PATH="/usr/lib/jvm/java-8-openjdk/bin/:$PATH"
  export JAVA_HOME="/usr/lib/jvm/java-8-openjdk"

  mvn package
}

package() {
  cd "$pkgname"

  # wrapper script
  install -vDm755 "$srcdir/wrapper.sh" "$pkgdir/usr/bin/$pkgname"

  # jar
  install -vDm644 "target/$pkgname-$pkgver.jar" "$pkgdir/usr/share/java/$pkgname/$pkgname.jar"

  # license
  install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" LICENSE

  # documentation
  install -vDm644 -t "$pkgdir/usr/share/doc/$pkgname" README.md
}
